package com.jichaoyun.sys.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jichaoyun.sys.mapper.*;
import com.jichaoyun.common.enums.MyExceptiontType;
import com.jichaoyun.common.ex.MyException;
import com.jichaoyun.model.entity.PriceChange;
import com.jichaoyun.model.entity.StationInfo;
import com.jichaoyun.model.vo.PriceChangeVo;

import com.jichaoyun.sys.mapper.*;
import com.jichaoyun.sys.service.IPriceChangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
* @author zhen
* @description 针对表【price_change】的数据库操作Service实现
* @createDate 2023-12-08 19:50:38
*/
@Service
@Slf4j
public class PriceChangeServiceImpl extends ServiceImpl<PriceChangeMapper, PriceChange>
    implements IPriceChangeService {

    @Autowired
    private RechargeinfoMapper rechargeinfoMapper;

    @Autowired
    private RealdataMapper realdataMapper;

    @Autowired
    private StationInfoMapper stationInfoMapper;
    private BigDecimal newPrice;

    @Autowired
    private SmsCacheMapper smsCacheMapper;



    /**
     * 汽费调整
     * @param model
     */
    @Override
    @Transactional
    public void startPriceChange(PriceChangeVo model) {
        StationInfo stationInfo = this.stationInfoMapper.selectById(model.getStationId());
        if(stationInfo==null){
            throw new MyException(MyExceptiontType.Other,"站点ID不正确");
        }
        PriceChange entity = new PriceChange();
        entity.setIsUse(false);
        entity.setStartTime(model.getStartTime());
        entity.setUnitPrice(model.getNewPrice());
        entity.setStationName(stationInfo.getStationName());
        entity.setStationId(model.getStationId());
        this.baseMapper.insert(entity);
    }

}




